package com.sie.plm.rpm.standar.controller.team;


import com.alibaba.fastjson.JSON;
import com.hustcad.plm.rpm.model.dto.active.ImportActiveDTO;
import com.hustcad.plm.rpm.model.dto.team.ImportTeamDTO;
import com.hustcad.plm.rpm.model.dto.team.TeamTree4InsertRoleDTO;
import com.sie.plm.rpm.standar.service.project.StandarProjectService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hustcad.plm.rpm.util.response.ResponseResult;
import io.swagger.annotations.ApiOperation;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;

@RestController
@Api(tags = {"标准版项目团队同步到产品库"})
@RequestMapping({"/api/v1/standar/projectTeam"})
public class StandarProjectTeamController {
    private static final Logger log = LoggerFactory.getLogger(StandarProjectTeamController.class);


    @Autowired
    private StandarProjectService standarProjectService;


    @PutMapping({"/standarInsertProjectManager"})
    @ApiOperation(value = "标准版添加项目经理或项目管理员", produces = "application/json; charset=utf-8")
    public ResponseResult<Boolean> standarInsertProjectManager(@RequestBody Map<String, Object> pmMap) {
        log.info("standarInsertProjectManager request Param {}", JSON.toJSONString(pmMap));
        this.standarProjectService.standarInsertProjectManager(pmMap);
        return ResponseResult.success(Boolean.valueOf(true));
    }

    @PutMapping({"/standarInsertRoleAndUser"})
    @ApiOperation(value = "标准版添加角色和用户", produces = "application/json; charset=utf-8")
    public ResponseResult<Boolean> standarInsertRoleAndUser(@RequestBody TeamTree4InsertRoleDTO data) {
        log.info("standarInsertRoleAndUser request Param {}", JSON.toJSONString(data));
        this.standarProjectService.standarInsertRoleAndUser(data);
        return ResponseResult.success(Boolean.valueOf(true));
    }

    @DeleteMapping({"/standarDeleteProjectManager"})
    @ApiOperation(value = "标准版移除项目经理或项目管理员", produces = "application/json; charset=utf-8")
    public ResponseResult<Boolean> standarDeleteProjectManager(@RequestBody Map<String, Object> pmMap) {
        log.info("standarDeleteProjectManager request Param {}", JSON.toJSONString(pmMap));
        this.standarProjectService.deleteStandarProjectManager(pmMap);
        return ResponseResult.success();
    }

    @DeleteMapping({"/standarDeleteRoleAndUser"})
    @ApiOperation(value = "标准版移除角色和成员", produces = "application/json; charset=utf-8")
    public ResponseResult<Boolean> standarDeleteRoleAndUser(@RequestBody TeamTree4InsertRoleDTO data) {
        log.info("standarDeleteRoleAndUser request Param {}", JSON.toJSONString(data));
        this.standarProjectService.standarDeleteRoleAndUser(data.getTeamTreeDTO());
        return ResponseResult.success(Boolean.valueOf(true));
    }

    @PostMapping({"/standarImportTeamByTemplate"})
    @ApiOperation(value = "标准版导入团队", produces = "application/json; charset=utf-8")
    public ResponseResult<Boolean> standarImportTeamByTemplate(@RequestBody ImportTeamDTO data) {
        log.info("standarImportTeamByTemplate request Param {}", JSON.toJSONString(data));
        this.standarProjectService.standarImportTeamByTemplate(data);
        return ResponseResult.success(Boolean.valueOf(true));
    }


    @PostMapping({"/standarImportPlanActiveByPlanTemplate"})
    @ApiOperation(value = "标准版通过计划导入活动", produces = "application/json; charset=utf-8")
    public ResponseResult<Boolean> standarImportPlanActiveByPlanTemplate(@RequestBody ImportActiveDTO importActiveDTO) {
        log.info("standarImportPlanActiveByPlanTemplate request Param {}", JSON.toJSONString(importActiveDTO));
        this.standarProjectService.standarImportPlanActiveByPlanTemplate(importActiveDTO);
        return ResponseResult.success(Boolean.valueOf(true));
    }
}
